/* GUI CONVERTED from rcsomte.p (converter v1.76) Mon Jun 10 11:10:14 2002 */
/* rcsomte.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.14.2.14 $                                                    */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 8.5      LAST MODIFIED: 05/29/96   BY: ame *J0PC*               */
/* REVISION: 8.5      LAST MODIFIED: 06/10/96   BY: ajw *J0RV*               */
/* REVISION: 8.6      LAST MODIFIED: 09/20/96   BY: cjt *K005*               */
/* REVISION: 8.6      LAST MODIFIED: 12/04/96   BY: jpm *K02X*               */
/* REVISION: 8.6      LAST MODIFIED: 02/12/97   BY: *J1HR* Ajit Deodhar      */
/* REVISION: 8.6      LAST MODIFIED: 04/30/97   BY: *K0CT* Kieu Nguyen       */
/* REVISION: 8.6      LAST MODIFIED: 06/03/97   BY: *K0DQ* Taek-Soo Chang    */
/* REVISION: 8.6      LAST MODIFIED: 09/18/97   BY: *H1FC* Seema Varma       */
/* REVISION: 8.6      LAST MODIFIED: 10/15/97   BY: *J233* Aruna Patil       */
/* REVISION: 8.6      LAST MODIFIED: 11/17/97   BY: *J26C* Aruna Patil       */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 07/15/98   BY: *L024* Bill Reckard      */
/* REVISION: 8.6E     LAST MODIFIED: 03/11/99   BY: *K200* Poonam Bahl       */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Robin McCarthy    */
/* REVISION: 9.1      LAST MODIFIED: 11/01/99   BY: *N004* Patrick Rowan     */
/* REVISION: 9.1      LAST MODIFIED: 01/19/00   BY: *N077* Vijaya Pakala     */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 04/11/00   BY: *J3PK* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 09/27/00   BY: *N0WD* Mudit Mehta       */
/* Revision: 1.14.2.9    BY: Katie Hilbert   DATE: 04/01/01 ECO: *P002*      */
/* Revision: 1.14.2.10   BY: Rajiv Ramaiah   DATE: 07/20/01 ECO: *M1FM*      */
/* Revision: 1.14.2.11   BY: Rajesh Kini     DATE: 01/23/02 ECO: *N189*      */
/* Revision: 1.14.2.12   BY: Patrick Rowan   DATE: 01/08/01 ECO: *P00G*      */
/* Revision: 1.14.2.13   BY: Katie Hilbert   DATE: 04/15/02 ECO: *P03J*      */
/* $Revision: 1.14.2.14 $  BY: Katie Hilbert   DATE: 06/10/02 ECO: *P083*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* SCHEDULED ORDER MAINT */

{mfdeclre.i}
{cxcustom.i "RCSOMTE.P"}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input-output parameter so_recid     as recid.
define input-output parameter endok        as logical.
define input parameter using_seq_schedules like mfc_logical no-undo.
define input parameter shipto              like scx_shipto no-undo.
define input parameter consignment         as logical.
define output parameter seq_sched_order    like mfc_logical no-undo.
define output parameter p_socmmts          like soc_hcmmts.

define new shared variable so_db      like dc_name.
define new shared variable all_days   like soc_all_days.
define new shared variable all_avail  like soc_all_avl.
define new shared variable sotax_trl  like tax_trl.
define new shared variable tax_recno  as recid.
define new shared variable l_edittax  like mfc_logical
                                      initial no no-undo.

define shared variable cmtindx        like cmt_indx.
define shared variable order-shipfrom like scx_shipfrom no-undo.
define shared variable impexp         like mfc_logical no-undo.
define shared variable global_order   as character.
define shared variable tax_in         like ad_tax_in.
define shared variable undo_sosomtb   like mfc_logical.
define shared variable so_recno       as recid.
define shared variable new_order      like mfc_logical.

define variable imp-okay              like mfc_logical no-undo.
define variable old_tr_days           as decimal no-undo.
define variable old_bill              as character.
define variable valid_acct            like mfc_logical.
define variable mc-error-number       like msg_nbr no-undo.

define shared frame so.
define shared frame so1.
define shared frame so2.
define shared frame sod.
define shared frame sod1.
define shared frame sod2.
define shared frame so3.

define buffer bill_cm for cm_mstr.
/* CONSIGNMENT VARIABLES */
define variable proc_id as character no-undo.
{socnvars.i}
using_cust_consignment = consignment.

/* TAX MANAGEMENT FORM */
FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
so_tax_usage colon 25
   so_tax_env  colon 25
 SKIP(.4)  /*GUI*/
with frame set_tax row 8 centered overlay side-labels NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-set_tax-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame set_tax = F-set_tax-title.
 RECT-FRAME-LABEL:HIDDEN in frame set_tax = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame set_tax =
  FRAME set_tax:HEIGHT-PIXELS - RECT-FRAME:Y in frame set_tax - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME set_tax = FRAME set_tax:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame set_tax:handle).

{gptxcdec.i}    /* DECLARATIONS FOR gptxcval.i */

if no then find first sod_det no-lock.

{rcordfrm.i}

find first soc_ctrl no-lock.
find first iec_ctrl no-lock no-error.

if using_seq_schedules then do:
   for first rcf_ctrl no-lock:
   end.
   if not available rcf_ctrl then do:
      create rcf_ctrl.
      if recid(rcf_ctrl) = -1 then.
   end.
end.

find so_mstr
   where recid(so_mstr) = so_recid exclusive-lock.

assign
   so_auto_inv     = substring(so_inv_mthd,2,1) = "y"
   so_wk_offset    = integer(substring(so_conrep,1,1))
   so_translt_days = decimal(substring(so_conrep,2,6))
   so_translt_hrs  = decimal(substring(so_conrep,8,6))
   so_cumulative   = substring(so_conrep,14,1) = "y"
   socmmts         = (so_cmtindx <> 0 or (new so_mstr and soc_hcmmts))
   print_ih        = (so_inv_mthd begins "b" or so_inv_mthd begins "p"
                      or so_inv_mthd = "" or so_inv_mthd begins " ")
   edi_ih          = (so_inv_mthd begins "b" or so_inv_mthd begins "e")
   old_bill        = so_bill.

if new_order and using_seq_schedules then
   so_seq_order = rcf_sch_default.

/* SET THE IMPORT/EXPORT FLAG TO YES IF ie_mstr IS AVAILABLE */
impexp = no.
/* SET THE DEFAULT VALUE BASED ON IEC_CTRL FILE */
if available iec_ctrl and iec_impexp = yes then impexp = yes.
{&RCSOMTE-P-TAG1}

display
   so_ar_acct
   so_ar_sub
   so_ar_cc
   so_taxable
   so_taxc
   so_auto_inv
   impexp
   so_wk_offset
   so_incl_iss
   so_cumulative
   so_consignment
   so_bill
   so_shipvia
   so_fob
   so_translt_days
   so_custref_val
   print_ih
   edi_ih
   so_print_pl
   socmmts
   so_site
   so_seq_order
   so_channel
   so_bump_all
   so_cum_acct
   so_curr
   so_userid
   so_rmks
with frame so1.

setb:
do with frame so1 on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


   hide frame so2.

   old_tr_days = so_translt_days.
   set
      so_ar_acct
      so_ar_sub
      so_ar_cc
      so_taxable
      so_taxc
      so_wk_offset
      so_incl_iss
      so_cumulative
      so_consignment
      so_bill
      so_auto_inv
      impexp
      so_seq_order when (using_seq_schedules and rcf_active)
      so_bump_all
      so_shipvia
      so_fob
      so_translt_days
      so_custref_val
      print_ih
      edi_ih
      so_print_pl
      socmmts
      so_site
      so_channel
      so_cum_acct
      so_curr   when (new_order)
      so_rmks
   with frame so1.

   assign
      substring(so_inv_mthd,2,1) = substring(string(so_auto_inv),1,1)
      substring(so_conrep,1,1)   = string(so_wk_offset,"9")
      substring(so_conrep,2,6)   = string(so_translt_days,"999.99")
      substring(so_conrep,8,6)   = string(so_translt_hrs,"999.99")
      substring(so_conrep,14,1)  = string(so_cumulative,"y/n")
      .

   {gprunp.i "gpglvpl" "p" "initialize"}
   /* SET PROJECT VERIFICATION TO NO */
   {gprunp.i "gpglvpl" "p" "set_proj_ver" "(input false)"}
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input  so_ar_acct,
        input  so_ar_sub,
        input  so_ar_cc,
        input  """",
        output valid_acct)"}

   if not valid_acct then do:
      next-prompt so_ar_acct with frame so1.
      undo, retry.
   end.

   if so_curr <> base_curr then do:
      find ac_mstr where ac_code = so_ar_acct no-lock no-error.
      if available ac_mstr and ac_curr <> so_curr
         and ac_curr <> base_curr then do:
         /* Account currency must match base or transaction currency */
         {pxmsg.i &MSGNUM=134 &ERRORLEVEL=3}
         next-prompt so_ar_acct.
         undo, retry.
      end.
   end.

   {gptxcval.i &code=so_mstr.so_taxc &frame=so1}

   if print_ih then do:
      if edi_ih then
         substring(so_inv_mthd,1,1) = "b".
      else
         substring(so_inv_mthd,1,1) = "p".
   end.
   else do:
      if edi_ih then
         substring(so_inv_mthd,1,1) = "e".
      else
         substring(so_inv_mthd,1,1) = "n".
   end.

   do for bill_cm:
      find bill_cm where bill_cm.cm_addr = so_bill no-lock no-error.

      if not available bill_cm then do:
         /* Not a valid customer */
         {pxmsg.i &MSGNUM=3 &ERRORLEVEL=3}
         next-prompt so_bill.
         undo , retry.
      end.

      if not new_order
         and old_bill <> so_bill
         and bill_cm.cm_curr <> so_curr then do:
         /* CUSTOMER BILL-TO CURRENCY DOES NOT MATCH */
         /* SALES ORDER CURRENCY                     */
         {pxmsg.i &MSGNUM=2018 &ERRORLEVEL=2}
      end.

   end.

   if new_order and base_curr <> so_mstr.so_curr then do:

      /* Validate currency */
      {gprunp.i "mcpl" "p" "mc-chk-valid-curr"
         "(input  so_curr,
           output mc-error-number)" }
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
         next-prompt so_curr.
         undo setb, retry setb.
      end.

      /* Calculate exchange rate & create usage records */
      {gprunp.i "mcpl" "p" "mc-create-ex-rate-usage"
         "(input  so_curr,
           input  base_curr,
           input  so_ex_ratetype,
           input  today,
           output so_ex_rate,
           output so_ex_rate2,
           output so_exru_seq,
           output mc-error-number)" }
      if mc-error-number <> 0 then do:
         {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
         next-prompt so_curr.
         undo setb, retry setb.
      end.

   end.  /* if new_order */

   /* SET EXCHANGE RATE */
   /* Allow change to exrate only when new because tr_hist created */
   if new_order or so_conf_date = ? then do:
      {gprunp.i "mcui" "p" "mc-ex-rate-input"
         "(input        so_curr,
           input        base_curr,
           input        today,
           input        so_exru_seq,
           input        true, /* update fixed-rate field */
           input        frame so1:row + 6,
           input-output so_ex_rate,
           input-output so_ex_rate2,
           input-output so_fix_rate)"}
   end.  /* if new_order */

   /* GET HEADER TAX DATA */
   assign
      so_recno = recid(so_mstr)
      undo_sosomtb = true.
   {&RCSOMTE-P-TAG2}
   {gprun.i ""sosomtb.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   if undo_sosomtb then undo, retry.

   /*! IF THE TRANSPORT DAYS FIELD HAS BEEN MODIFIED,
   UPDATE EACH LINE SO THE REQUIRED SCHEDULE UPDATE
   PROGRAM WILL SEE THE CHANGES */
   if so_translt_days <> old_tr_days then
      for each scx_ref where scx_order = so_nbr
         no-lock:
         find sod_det where sod_nbr = so_nbr and
            sod_line = scx_line
         exclusive-lock no-error.
         if available sod_det then
            sod_sched_chgd = yes.
      end.

   /* IF IMPORT EXPORT FLAG IS SET TO YES CALL THE IMPORT EXPORT */
   /* CREATE ROUTINE TO CREATE ie_mstr ied_det AND UPDATE  ie_mstr   */
   hide frame so1.

   /* DETERMINE IF SEQUENCE SCHEDULE POP-UP IS TO DISPLAY */
   if using_seq_schedules then
      run sequence_schedule_info
         (input so_recid,
          input shipto,
          input using_seq_schedules,
          input rcf_active,
          input rcf_inc_in_rss,
          input rcf_firm_seq_days,
          input-output so_seq_order).
   hide frame so3.

   /* DETERMINE IF CUSTOMER CONSIGNMENT POP-UP IS TO DISPLAY */
   if using_cust_consignment and so_consignment then do:
      proc_id = "popup-update".
      {gprunmo.i
         &program=""socnso.p""
         &module="ACN"
         &param="""(input proc_id,
           input so_nbr,
           input so_ship,
           input so_site,
           input yes)"""}

   end.  /* if using_cust_consignment and so_consignment */

   seq_sched_order = so_seq_order.

   /* ADDED LOGIC : EXCLUDE PLANNING DATA (SO__QADL02) IS    */
   /* IS ENABLED ONLY WHEN MERGE RSS IS YES.                 */
   /* ALSO, WHEN MERGE RSS IS NO, EXCLUDE PLANNING DATA IS   */
   /* DISABLED AND SET TO NO IRRESPECTIVE OF THE INPUT VALUE */

   if not so_cum_acct then
      update
         so_ship_cmplt
         so_merge_rss
         so_auth_days
         so__qadl02
      with frame so2
      editing:

         if input so_merge_rss = yes
         then
            enable so__qadl02 with frame so2.

         else do:
            so__qadl02 = no.
            display so__qadl02 with frame so2.
            disable so__qadl02 with frame so2.
         end. /* ELSE DO */

        readkey.
         apply lastkey.

      end. /* EDITING */

   if impexp then do:
      imp-okay = no.
      {gprun.i ""iemstrcr.p"" "(input ""1"",
                                input so_nbr,
                                input recid(so_mstr),
                                input-output imp-okay )"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if imp-okay = no then do:
         view frame  so .
         undo , retry.
      end.
   end.
   p_socmmts = socmmts.
   endok = true.
end.
/*GUI*/ if global-beam-me-up then undo, leave.


/* PROCEDURE TO DETERMINE IF SEQUENCE SCHEDULE POP-UP IS TO DISPLAY */
PROCEDURE sequence_schedule_info:

   define input parameter so_recid as recid no-undo.
   define input parameter shipto like scx_shipto no-undo.
   define input parameter installed like mfc_logical no-undo.
   define input parameter seq_active like mfc_logical no-undo.
   define input parameter include_seq_in_rss like mfc_logical no-undo.
   define input parameter firm_days like rcf_firm_seq_days no-undo.
   define input-output parameter seq_order like mfc_logical no-undo.

   for first so_mstr where recid(so_mstr) = so_recid
      exclusive-lock:
   end.

   if installed and seq_active and seq_order then do:

      if new_order then do:

         for first rcc_mstr where
            rcc_addr = shipto no-lock:
         end.

         if available rcc_mstr then
            assign
               so_firm_seq_days = rcc_firm_seq_days
               so_inc_in_rss = rcc_inc_in_rss.
         else
            assign
               so_inc_in_rss = include_seq_in_rss
               so_firm_seq_days = firm_days.
      end.  /*IF NEW_ORDER*/

      display
         so_inc_in_rss
         so_firm_seq_days
      with frame so3.

      setloop1:
      do on error undo, leave:
/*GUI*/ if global-beam-me-up then undo, leave.


         set
            so_inc_in_rss
            so_firm_seq_days
         with frame so3.

         if so_firm_seq_days < 0 then do:
            /* NEGATIVE AMOUNTS NOT ALLOWED */
            {pxmsg.i &MSGNUM=228 &ERRORLEVEL=3}
            next-prompt so_firm_seq_days with frame so3.
            undo, retry setloop1.
         end.
         seq_order = so_seq_order.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end. /* if installed */

END PROCEDURE.
